package org.NooLab.glue.net.http.rest;

 
import java.util.Vector;

import org.restlet.Application;
import org.restlet.Component;
import org.restlet.Restlet;
import org.restlet.data.Protocol;
import org.restlet.routing.Router;

  

public class _RestletHttpServer extends Application{

	Application application;
	Router routingRoot ;
	
	RestletServerFactory restSrvFactory ;
	
	Vector<Component> components = new Vector<Component>() ; 
	 
	
	public _RestletHttpServer( ){
		
	}
	
	public void setServer( RestletServerFactory restsrvfactory){
		Component component ;
		
		restSrvFactory = restsrvfactory;
		
		component = new Component();
		component.getServers().add( Protocol.HTTP, restSrvFactory.getServerPort() );
		 
		// Create an application
		application = new _RestletHttpServer();

		// Attach the application to the component and start it
		component.getDefaultHost().attachDefault(application);
		
		components.add(component) ;

	}
	
	public void startComponents(){
		
		try {

			components.get(0).start();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
    @Override
    public Restlet createInboundRoot() {
    	int n;
    	
        // Create a router : root router
        routingRoot = new Router(getContext());

        // Attach the resources to the router
        // in our case, the references are provided by the factory via getDomainMappings()
        
        n = restSrvFactory.getDomainMappings().size() ;
        // router.attach("/users/{user}", UserResource.class );
        // router.attach("/users/{user}/orders", OrdersResource.class );
        // router.attach("/users/{user}/orders/{order}", OrderResource.class );

        // Return the root router
        return routingRoot;
    }

	
}
